package com.iacrqq.sedaf.demo.sHttpServer;

import com.iacrqq.sedaf.application.Application;
import com.iacrqq.sedaf.application.ApplicationFactory;

/**
 * 
 * Implement a HTTP Server using SEDA
 * 
 * One HTTP request divided to 4 stage:
 *	1. Accept connection
 *	2. Parse request，included read request data
 *  3. Process request, read file, make response
 *  4. Send response to client
 * 
 * @author sihai
 *
 */
public class SHttpServer
{
	private static final String SHTTP_SERVER_CONFIG_FILE = "sHttpServer.xml";
	public static void main(String[] args)
	{
		try
		{
			Application application = ApplicationFactory.createApplication(Thread.currentThread().getContextClassLoader().getResource(SHTTP_SERVER_CONFIG_FILE).getFile());
			application.init(application.getConfiguration());
			application.start();
			application.startAdaptiveAjust();
			
			// 运行10 Minutes
			try
			{
				Thread.sleep(60000 * 10);
			}
			catch(InterruptedException e)
			{
				e.printStackTrace();
			}
			
			application.stopAdaptiveAjust();
			application.stop();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}
